﻿using System;
using System.Collections.Generic;
using System.Linq; 
using NTTDATA.BEENChina.ResultCertification.Config;

namespace NTTDATA.BEENChina.ResultCertification.Checker.Date
{
    [Serializable]
    [VerfityAttribute(Id = "VerfityRq0226", Name = "年月日_完整度检证", CategoryType = EnumCategoryType.日期, Model = true)]
    public class VerfityRq0226:VerfityOneResult
    {

        /// <summary>
        /// 只判断年月日部分是否不完整
        /// </summary>
        private readonly string[] _dateFormats = new[] {  "yy", "yyyy", "MM", "dd"};

        /// <summary>
        /// 20130927
        /// 全是空白的录入结果 不进行验证
        /// 
        /// 20131011
        /// 如果只有一个问号
        /// 忽略
        /// </summary>
        /// <param name="result"></param>
        /// <param name="entryCommon"></param>
        /// <returns></returns>
        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult = false;

            foreach (var rowResult in result)
            {
             
                foreach (var entryResult in rowResult)
                {
                    //如果结果只是一个问号
                    //忽略
                    if (entryResult.Replace("/", string.Empty).Equals("?"))
                    {
                        continue;
                    }


                    List<string> entry = entryResult.Split(new char[] { '/' }).ToList();

                    int emptyColumnCount = base.EmptyColumnCount(entry);

                    if (emptyColumnCount == entry.Count)
                    {
                        continue;
                    }
                    

                    List<string> arrayDateFormat = ChildImageObject.CategorySetting.DataFormat.Split(new char[] { '/' }).ToList();
                     
                    //只对比年月日
                    IEnumerable<string> foramts = arrayDateFormat.Intersect(_dateFormats);


                    foreach (string format in foramts)
                    {
                        int index = arrayDateFormat.IndexOf(format);

                        string entrypart = index > -1 ? entry[index] : "@";

                        bresult = string.IsNullOrEmpty(entrypart);

                        if (bresult) break;
                    }
                    if (bresult) break;
                }
                if (bresult) break;
            }
             
  

            if (bresult)
            {
                System.Console.WriteLine("VerfityRq0226");
            }

            return bresult;   
        }
         

        

    }
}